package com.universalInterface.lims_interface.controller;


import cn.hutool.core.bean.BeanUtil;
import com.universalInterface.common.result.ApiResult;
import com.universalInterface.lims_interface.entity.LabInfo;
import com.universalInterface.lims_interface.service.ILabInfoService;
import com.universalInterface.lims_interface.vo.labinfo.GetLabInfoVo;
import com.universalInterface.lims_interface.vo.labinfo.LabInfoSaveVo;
import com.universalInterface.lims_interface.vo.labinfo.LabInfoUpdateVo;
import com.universalInterface.lims_interface.vo.labinfo.param.GetLabInfoParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 实验室信息
 * </p>
 *
 * @author Lx
 * @since 2023-12-19
 */
@Tag(name = "实验室信息")
@Validated
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/labInfo")
public class LabInfoController {

	private final ILabInfoService iLabInfoService;

	@Operation(summary = "新增实验室")
	@PostMapping("/save")
	public ApiResult save(@Parameter(name = "LabInfoSaveVo", description = "实验室新增对象") @Valid @RequestBody LabInfoSaveVo saveVo) {
		LabInfo labInfo = iLabInfoService.save(BeanUtil.copyProperties(saveVo, LabInfo.class));
		return ApiResult.success("新增成功！");
	}

	@Operation(summary = "通过id更新实验室")
	@PutMapping("/updateById")
	public ApiResult updateById(@Parameter(name = "LabInfoUpdateVo", description = "实验室更新对象") @Valid @RequestBody LabInfoUpdateVo updateVo) {
		Integer i = iLabInfoService.updateById(BeanUtil.copyProperties(updateVo, LabInfo.class));
		return ApiResult.success("更新成功！size = " + i);
	}

	@Operation(summary = "通过id删除实验室")
	@DeleteMapping("/deleteById")
	public ApiResult deleteById(@Parameter(name = "id", description = "主键id") @NotNull @RequestParam(value = "id") Long id) {
		Integer i = iLabInfoService.deleteById(id);
		return ApiResult.success("删除成功！size = " + i);
	}

	@Operation(summary = "查询单个实验室信息")
	@PostMapping("/get")
	public ApiResult get(@Parameter(description = "查询单个实验室参数") @Valid @RequestBody GetLabInfoParam param) {
		LabInfo data = iLabInfoService.get(BeanUtil.copyProperties(param, LabInfo.class));
		return ApiResult.success("查询成功！", BeanUtil.copyProperties(data, GetLabInfoVo.class));
	}

}
